<?php
namespace waf\server;

use \waf\Waf;
use \waf\log\Log;
use \waf\server\BaseServer;
use \Yaf;

class UdpServer extends BaseServer
{
    public function init()
    {
        Log::logSystem("in", __FILE__, __LINE__, __FUNCTION__);
        $this->strServerType = 'udp';
        parent::init();
        Log::logSystem("out", __FILE__, __LINE__, __FUNCTION__);
    }

    public function onPacket($objSServer, $data, $arrAddr)
    {
        Log::logSystem("onPacket", __FILE__, __LINE__, __FUNCTION__);
        $request_uri = $this->route($data);
        ob_start();
        try {
            $requestObj = new \Yaf_Request_Http($request_uri);
            $this->objYaf->getDispatcher()->dispatch($requestObj);
        } catch (\Yaf_Exception $e) {
            Log::logError("yaf_exception:".print_r($e, true), __FILE__, __LINE__, __FUNCTION__);
        }
        $result = ob_get_contents();
        ob_end_clean();
        $objSServer->sendto($arrAddr['address'], $arrAddr['port'], $result);
    }
}
?>